/*
 * Copyright By ZATI
 * Copyright By 3a3c88295d37870dfd3b25056092d1a9209824b256c341f2cdc296437f671617
 * All rights reserved.
 *
 * If you are not the intended user, you are hereby notified that any use, disclosure, copying, printing, forwarding or
 * dissemination of this property is strictly prohibited. If you have got this file in error, delete it from your system.
 */

package cn.wzc.crystal.platform.support;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;

import java.io.Serializable;

/**
 * api 响应接口
 * 用于封装响应输出的基本属性
 */
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public final class ApiResult implements Code, Serializable {

	private final String code;
	private final String message;
	private final Object data;

	// ========================= 构造函数 =========================

	public ApiResult(String code, String message, Object data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public ApiResult(String code, Object data) {
		this(code, null, data);
	}

	public ApiResult(String code, String message) {
		this(code, message, null);
	}

	public ApiResult(Code code) {
		this(code.getCode(), code.getMessage(), null);
	}

	public ApiResult(Code code, String message) {
		this(code.getCode(), message, null);
	}

	public ApiResult(Code code, Object data) {
		this(code.getCode(), code.getMessage(), data);
	}

	// ========================= 工厂方法 =========================

	public static ApiResult of(String code, String message, Object data) {
		return new ApiResult(code, message, data);
	}

	public static ApiResult of(String code, String message) {
		return new ApiResult(code, message, null);
	}

	public static ApiResult of(Code code) {
		return ApiResult.of(code.getCode(), code.getMessage(), null);
	}

	public static ApiResult of(Code code, String message) {
		return ApiResult.of(code.getCode(), message, null);
	}

	public static ApiResult of(Code code, Object data) {
		return ApiResult.of(code.getCode(), code.getMessage(), data);
	}


}
